package com.hksj.common.core.executor;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author fjt
 * @data 2024/8/8 18:04
 * @describe todo
 */

@Configuration
@EnableAsync
public class ThreadPoolConfig {



    /**
     * 任务线程池
     *
     * @return
     */
    @Bean("energyConsumptionTaskExecutor")
    public Executor energyConsumptionTaskExecutor() {
        MyThreadPoolTaskExecutor threadPoolExecutor = new MyThreadPoolTaskExecutor(Runtime.getRuntime().availableProcessors(),
                // 获取可用CPU数
                Runtime.getRuntime().availableProcessors(),
                // 存活时长
                30,
                1000,
                "energy_consumption",
                new ThreadPoolExecutor.CallerRunsPolicy());
        return threadPoolExecutor;
    }


}
